package com.example.nuc_ms_beta.ui.activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.example.nuc_ms_beta.R;
import com.example.nuc_ms_beta.app.MyApplication;
import com.example.nuc_ms_beta.bean.competeactivity.CompeteMoreListView;
import com.example.nuc_ms_beta.ui.viewconstruction.adapter.CompeteDetailAdapter;

import java.util.List;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;

/**
 * Created by bnhc on 17-6-4.
 */

public class CompeteDetailActivity extends Activity {

    private ImageView activity_competetail_iv;
    private TextView activity_competetail_tv;
    private ListView activity_competetail_lv;
    private String imageUrl;
    private String title;
    private String type;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_competedetail);
        imageUrl = getIntent().getStringExtra("imageUrl");
        title = getIntent().getStringExtra("topic");
        type = getIntent().getStringExtra("type");
        initView();
        querrDate();
    }

    private void initView() {
        activity_competetail_iv = (ImageView) findViewById(R.id.activity_competetail_iv);
        Glide.with(MyApplication.context)
                .load(imageUrl)
                .into(activity_competetail_iv);
        activity_competetail_tv = (TextView) findViewById(R.id.activity_competetail_tv);
        activity_competetail_tv.setText(title.toString());
        activity_competetail_lv = (ListView) findViewById(R.id.activity_competetail_lv);
    }

    private void querrDate() {
        BmobQuery<CompeteMoreListView> queryDate = new BmobQuery<>();
        queryDate.addWhereEqualTo("CompeteDatil_Type", type);
        queryDate.findObjects(new FindListener<CompeteMoreListView>() {

            @Override
            public void done(List<CompeteMoreListView> list, BmobException e) {
                if (e == null) {
                    if (list.size() > 0) {
                        activity_competetail_lv.setAdapter(new CompeteDetailAdapter(CompeteDetailActivity.this, list, R.layout.activity_competedetail_item));
                    }
                } else {
                    Toast.makeText(CompeteDetailActivity.this, "Error", Toast.LENGTH_SHORT).show();
                }
            }
        });

    }
}
